package com.company.card_service.controller;


import com.company.card_service.model.Employee;
import com.company.card_service.serviceImpl.EmployeeServiceImpl;
import com.company.card_service.util.AliOssCloudUtil1;
import com.company.card_service.util.PageHelper;
import com.company.card_service.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.http.fileupload.FileItem;
import org.apache.tomcat.util.http.fileupload.disk.DiskFileItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端后台页面控制器
 * </p>
 *
 * @author 赵志浩
 * @since 2022-09-15 04:15:06
 */
@Slf4j
@RestController
@RequestMapping("admin/manger/employee")
@Api(value = "提供员工管理的相关接口",tags = "后台管理系统-员工管理")
public class EmployeeController {

    @Autowired
    EmployeeServiceImpl employeeService;

    @Autowired
    AliOssCloudUtil1 aliOssCloudUtil;

    @PostMapping("/addEmployee")
    @ApiOperation("增加员工")
    public Result addEmployee(@RequestParam(value = "file",required = false) MultipartFile files,Employee e){
        employeeService.saveAll(files,e);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage());
    }

    @PostMapping("/addEmployeeFor")
    @ApiOperation("增加员工(分开上传)")
    public Result addEmployeeFor(@RequestBody Employee e){
        employeeService.saveAllFor(e);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage());
    }

    @PostMapping("/updateEmployee")
    @ApiOperation("修改员工")
    public Result updateEmployee(@RequestParam(value = "file",required = false) MultipartFile files,Employee e){
        employeeService.saveAll(files,e);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage());
    }

    @PostMapping("/updateEmployeeFor")
    @ApiOperation("修改员工(分开上传)")
    public Result updateEmployeeFor(@RequestBody Employee e){
        employeeService.saveAllFor(e);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage());
    }

    @GetMapping("/RemoveEmployee/{id}")
    @ApiOperation("id删除员工")
    public Result RemoveEmployee(@PathVariable Long id){
        boolean b = employeeService.removeById(id);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(),b);
    }

    @GetMapping("/getEmployee/{id}")
    @ApiOperation("id获取员工")
    public Result getEmployee(@PathVariable Long id){
        Employee byId = employeeService.getById(id);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(),byId);
    }

    //通过员工id冻结员工
    @ApiOperation("冻结员工接口")
    @PutMapping("/deleteEmployee")
    @ApiImplicitParam(dataType = "int",name = "eid",value = "员工id",required = true)
    public Result deleteEmployee(int eid){
        Result result = employeeService.deleteEmployeeById(eid);
        return result;
    }

    @ApiOperation("后台分页员工接口")
    @PostMapping("/pageEmployeeQuery/{current}/{size}/{companyid}")
    public Result pageEmployeeQuery(@RequestBody(required = false) EmployeeQueryVo employeeQueryVo,
                                    @PathVariable Integer companyid,
                                    @PathVariable Integer current,
                                    @PathVariable Integer size){
        PageHelper pageHelper = employeeService.pageEmployeeQuery(employeeQueryVo,companyid,current,size);
        return Result.success(pageHelper);
    }

    @ApiOperation("后台各种排序显示分页员工接口")
    @PostMapping("/pageTypeEmployeeQuery/{current}/{size}/{typeId}/{companyid}")
    public Result pageTypeEmployeeQuery(
                                        @PathVariable Integer current,
                                        @PathVariable Integer size,
                                        @PathVariable Integer typeId,
                                        @PathVariable Integer companyid){
        PageHelper pageHelper = employeeService.pageEmployeeTypeQuery(current,size,typeId,companyid);
        return Result.success(pageHelper);
    }

    //
    @ApiOperation("优秀员工展示")
    @PutMapping("/excellentEmployee/{companyId}")
    public Result excellentEmployee(@PathVariable Integer companyId){
        List<PCEmployeeVo> list = employeeService.excellentEmployee(companyId);
        return Result.success(list);
    }

}

